<template>
    <a-modal
      :title="title"
      :visible="wechatVisible"
      :confirm-loading="confirmLoading"
      @cancel="cancel"
      @ok="ok"
    >
    
    <a-form-model ref="editwechatModel"  :model="wechatFormDatas"  layout="vertical" 
    :labelCol="{span: 8}" :wrapperCol="{span: 16}">
        <a-form-model-item label="标题" prop="title">
          <a-input v-model="wechatFormDatas.title"  placeholder="请输入标题" />
        </a-form-model-item>
        <a-form-model-item label="文字内容" prop="content">
          <a-input v-model="wechatFormDatas.content" type="textarea" placeholder="请输入文字内容" />
        </a-form-model-item>
        <a-form-model-item label="类型" prop="type">
          <a-select v-model="wechatFormDatas.type" placeholder="请选择类型">
            <a-select-option :value="0">图片</a-select-option>
            <a-select-option :value="1">视频</a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item v-if="wechatFormDatas.type==0" label="上传图片" prop="image_url">
          <upImages :url.sync="wechatFormDatas.image_url"></upImages>
        </a-form-model-item>
        <a-form-model-item v-if="wechatFormDatas.type==1" label="上传视频" prop="video_url">
          <upImages :url.sync="wechatFormDatas.video_url"></upImages>
        </a-form-model-item>
        <a-form-model-item label="状态" >
          <a-radio-group v-model="wechatFormDatas.status">
            <a-radio :value="1"> 正常 </a-radio>
            <a-radio :value="0"> 禁用 </a-radio>
          </a-radio-group>
        </a-form-model-item>
      </a-form-model>
    </a-modal>
  </template>
  
  <script>
  import { editWechatmessageListApi,addWechatmessageListApi } from '@/api/brand.js'
  export default {
    data() {
      return {
        wechatVisible:false,
        title:"添加",
        confirmLoading:false,
        loading:false,

        wechatFormDatas:{
          title:"",
          content:"",
          type:0,
          image_url:"",
          video_url:"",
          status:1,
        }
      }
    },
    created() {
    },
    methods: {
      openeditWechatmessage(json){
        this.wechatFormDatas={
          title:"",
          content:"",
          type:0,
          image_url:"",
          video_url:"",
          status:1,
        }
          this.title='添加'
        if(json){
          this.title='修改信息'
          this.wechatFormDatas=JSON.parse(JSON.stringify(json))
          this.wechatFormDatas.ids=json.id
        }
        this.wechatVisible=true
      },
      handleOk(){
        this.wechatVisible=false
      },
      cancel(){
        this.handleOk()
      },
      ok(){
        this.$refs.editwechatModel.validate(valid => {
          if (valid) {
            if(this.wechatFormDatas.ids){
              this.editLists()
            }else{
              this.addsLists()
            }
          }
        })
      },

      editLists(){
        editWechatmessageListApi({...this.wechatFormDatas,
        brand_id: process.env.VUE_APP_BRAND_ID}).then(res=>{
          this.$message.success("操作成功");
          this.handleOk()
          this.$emit("changes")
        })
      },
      addsLists(){
        addWechatmessageListApi({...this.wechatFormDatas,
        brand_id: process.env.VUE_APP_BRAND_ID}).then(res=>{
          this.$message.success("操作成功");
          this.handleOk()
          this.$emit("changes")
        })
      }



    }
  }
  </script>
  
  <style lang="less" scoped>
  </style>
  